package ch.dungegondefenders.playfield;

import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import ch.dungegondefenders.handler.FieldMouseEnter;
import ch.dungegondefenders.handler.FieldMouseExit;

public class FieldFactory {

	public static final int DEFAULT_WIDTH = 30;
	public static final int DEFAULT_HEIGHT = 30;

	private FieldDisplayTypes type;
	private FieldBehaviourTypes behaviour;
	private int width = 0;
	private int height = 0;
	private Shape shape;
	private Field field;

	public FieldFactory() {
	}

	public FieldFactory setDisplayType(FieldDisplayTypes type) {
		this.type = type;
		return this;
	}

	public FieldFactory setBehaviourType(FieldBehaviourTypes behaviour) {
		this.behaviour = behaviour;
		return this;
	}

	public FieldFactory setWidth(int width) {
		this.width = width;
		return this;
	}

	public FieldFactory setHeight(int height) {
		this.height = height;
		return this;
	}

	public Field build() {

		field = new Field();

		if (height == 0) {
			height = DEFAULT_HEIGHT;
		}
		field.setHeight(height);

		if (width == 0) {
			width = DEFAULT_WIDTH;
		}
		field.setWidth(width);

		if (behaviour == null) {
			behaviour = FieldBehaviourTypes.ACCESSIBLE_ENEMY_GROUND;
		}
		field.setBehaviour(behaviour);

		if (type == null) {
			type = FieldDisplayTypes.WHITE;
		}
		field.setDisplay(type);

		// erstelle Shape
		shape = new Rectangle(height, width);
		shape.setOnMouseEntered(new FieldMouseEnter(shape));
		shape.setOnMouseExited(new FieldMouseExit(shape));

		switch (type) {
		case BROWN:
			shape.setFill(Color.BROWN);
			break;
		case GREEN:
			shape.setFill(Color.GREEN);
			break;
		default:
			shape.setFill(Color.WHITE);
			break;
		}

		field.setShape(shape);

		return field;
	}

}
